$(function(){
		var gallery =$(".gallery2"),
		    imgBtnLeft =gallery.find(".imgLeft"),
			imgBtnRight =gallery.find(".imgRight"),
			listBtnLeft =gallery.find(".btnLeft"),
			listBtnRight =gallery.find(".btnRight");
			
		var ImgList = gallery.find(".galleryList li");
		var step = ImgList.outerWidth(true);
	
		var ListLength =ImgList.length;
	
	//默认显示
  	 Lchange(0,ImgList);
	 //点击图片列表切换事件
		ImgList.find("a").bind("click",function(){
			var _this = $(this).parent();
			
			Lchange(_this,ImgList);
			return false;
		});
		
	   //图片中上一页按钮切换事件
		imgBtnLeft.bind("click",function(){
			var Index = getIndex()-1;
			if(Index<=0){
				Index=ListLength-1;
				}
			 Lchange(Index,ImgList);	
			return false;	
		 });
		//图片中下一页按钮切换事件
		imgBtnRight.bind("click",function(){
			var Index = getIndex()+1;
			if(Index>=ListLength){
				Index=0;
				}
			 Lchange(Index,ImgList);	
			return false;	
		 });
		
		listBtnLeft.bind("click",function(){
			var offset =parseInt($(".galleryList").css("left"));
			if(offset<0){
				ListMove(step,-1);
				}	
			return false;	
		});
			listBtnRight.bind("click",function(){
			
			var offset =Math.abs(parseInt($(".galleryList").css("left")));
			if(offset<=(ListLength-7)*step){
				ListMove(step,1);
				}	
			return false;	
		});
});


//图片、标题、描述切换 
function Lchange(e,ImgList){
	var index = (e && 'object' == typeof e)?e.index():e,
		title = ImgList.eq(index).attr("Imgtitle"),
		
		imgSrc =ImgList.eq(index).children("a").attr("href");
		
	ImgList.eq(index).addClass("current").siblings().removeClass("current");
	$(".imgHolder #Big").attr("src",imgSrc).hide().fadeIn(900);
	$(".gallery2 .title").html(title);
	}
//获取图片列表焦点图片的索引
function getIndex(){
	var current = $(".galleryList li.current").index();
	return current;
	}

function ListMove(step,o){
	$(".galleryList").stop().animate({"left":"-="+step*o});
	}
